package com.wilmer.bankarea.mapper;

import java.util.List;

import com.wilmer.bankarea.domain.AreaVo;
import com.wilmer.bankarea.domain.BankArea;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 地区Mapper接口
 *
 * @author hans
 * @date 2024-03-31
 */
@Mapper
public interface BankAreaMapper {

    @Select("SELECT parent.area_id AS areaId, parent.name AS areaName, JSON_ARRAYAGG( JSON_OBJECT( 'areaId', child.area_id, 'areaName', child.name ) ) AS children FROM bank_area AS parent LEFT JOIN bank_area AS child ON child.parent_id = parent.area_id WHERE parent.parent_id = 0 GROUP BY areaId asc ORDER BY areaId  ASC")
    public List<BankArea> selectBankAreaList();

    @Select("SELECT area_id as value,name as label FROM bank_area WHERE parent_id !=0")
    public List<AreaVo> getArea();


}
